package com.pureut.production.controller;


import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.common.log.annotation.Log;
import com.pureut.common.log.enums.BusinessType;
import com.pureut.common.security.annotation.RequiresPermissions;
import com.pureut.production.domain.vo.LineWarehouseVo;
import com.pureut.production.service.LineWarehouseService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author: CM
 * @date: 2023/2/6  15:14
 */
@RestController
@RequestMapping("/lineWarehouse")
public class LineWarehouseController extends BaseController {

    @Resource
    private LineWarehouseService lineWarehouseService;

    /**
     * 获取线边仓库树状图列表
     */
    @GetMapping("/list")
    @RequiresPermissions("productionTube:shopAdministration:lineWarehouse:list")
    public AjaxResult list(LineWarehouseVo lineWarehouseVo) {
        return AjaxResult.success(lineWarehouseService.getList(lineWarehouseVo));
    }

    /**
     * 添加线边仓库
     */
    @Log(title = "新增线边仓库", businessType = BusinessType.INSERT)
    @RequiresPermissions("productionTube:shopAdministration:lineWarehouse:add")
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody LineWarehouseVo lineWarehouseVo) {
        return toAjax(lineWarehouseService.addWarehouse(lineWarehouseVo));
    }

    /**
     * 获取线边仓列表
     */
    @GetMapping("/lineList")
    public TableDataInfo lineList(LineWarehouseVo lineWarehouseVo) {
        startPage();
        return getDataTable(lineWarehouseService.getlineList(lineWarehouseVo));
    }

    /**
     * 查看线边仓
     */
    @GetMapping("/view/{warehouseCode}")
    public AjaxResult view(@PathVariable("warehouseCode") Long id) {
        return AjaxResult.success(lineWarehouseService.getView(id));
    }

    /**
     * 删除仓库
     */
    @Log(title = "删除仓库", businessType = BusinessType.DELETE)
    @RequiresPermissions("productionTube:shopAdministration:lineWarehouse:remove")
    @DeleteMapping("/delete/{warehouseCode}")
    public AjaxResult remove(@PathVariable("warehouseCode") Long id) {
        return toAjax(lineWarehouseService.deleteWarehouse(id));
    }

    /**
     * 修改仓库
     */
    @Log(title = "修改仓库", businessType = BusinessType.UPDATE)
    @RequiresPermissions("productionTube:shopAdministration:lineWarehouse:edit")
    @PostMapping("/update")
    public AjaxResult update(@Validated @RequestBody LineWarehouseVo lineWarehouseVo) {
        return toAjax(lineWarehouseService.updateWarehouse(lineWarehouseVo));
    }

    /**
     * 获取仓库列表
     */
    @GetMapping("/getWorkshop")
    public AjaxResult getWorkshop() {
        return AjaxResult.success(lineWarehouseService.getWorkshop());
    }





}
